package cn.yiyuan.base.service.impl;

import cn.yiyuan.base.mapper.BaseMapper;
import cn.yiyuan.base.query.BaseQuery;
import cn.yiyuan.base.service.BaseService;
import cn.yiyuan.base.until.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * @user m
 * @project car_mall_system
 * @date 2023-12-28
 * @package cn.yiyuan.base.service.impl
 */

public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public void insert(T dep) {
        mapper.insert(dep);
    }

    @Override
    public void delete(Serializable id) {
        mapper.delete(id);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public List<T> getAll() {
        return mapper.getAll();
    }

    @Override
    public T getById(Serializable id) {
        return mapper.getById(id);
    }

    @Override
    public void batch(List<Long> ids) {
        mapper.batch(ids);
    }

    @Override
    public PageInfo<T> queryPage(BaseQuery query) {
        //        查询总条数 包装类的默认值是null
        Long total = mapper.queryTotal(query);
        System.out.println(total);
//        查询分页数据  总数据
        if (total !=0){
            List<T> list = mapper.queryList(query);
            //返回数据
            return new PageInfo<T>(total,list);
        }
        return new PageInfo<T>();
    }
}
